use tauri::State;
use crate::core::AppState;
use crate::db::{ModelConfig, upsert_config, load_config, list_keys, delete_config, set_setting, get_setting};

#[tauri::command]
pub fn set_model_config(
    state: State<AppState>,
    key: String,
    config: ModelConfig,
) -> Result<(), String> {
    upsert_config(&state.db_path, &key, &config).map_err(|e| e.to_string())
}

#[tauri::command]
pub fn get_model_config(state: State<AppState>, key: String) -> Result<ModelConfig, String> {
    load_config(&state.db_path, &key).map_err(|_| "not found".to_string())
}

#[tauri::command]
pub fn list_model_keys(state: State<AppState>) -> Result<Vec<String>, String> {
    list_keys(&state.db_path).map_err(|e| e.to_string())
}

#[tauri::command]
pub fn delete_model_config(state: State<AppState>, key: String) -> Result<(), String> {
    delete_config(&state.db_path, &key).map_err(|e| e.to_string())
}

#[tauri::command]
pub fn set_app_setting(state: State<AppState>, key: String, value: String) -> Result<(), String> {
    set_setting(&state.db_path, &key, &value).map_err(|e| e.to_string())
}

#[tauri::command]
pub fn get_app_setting(state: State<AppState>, key: String) -> Result<Option<String>, String> {
    get_setting(&state.db_path, &key).map_err(|e| e.to_string())
}


